<template>
  <div>

    <el-form :model="queryParams" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库方" prop="storageParty">
        <el-input
          v-model="queryParams.storageParty"
          placeholder="请输入入库方"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库方" prop="outboundParty">
        <el-input
          v-model="queryParams.outboundParty"
          placeholder="请输入出库方"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库">
        <el-select v-model="queryParams.warehouseId" placeholder="请选择仓库">
          <el-option v-for="t in type" :label="t.warehouseName" :value="t.warehouseId" :key="t.warehouseId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="请选择状态">
          <el-option label="未出入库" value="0"></el-option>
          <el-option label="已入库" value="1"></el-option>
          <el-option label="已出库" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['cord:addr:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['cord:addr:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['cord:addr:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cord:addr:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          v-hasPermi="['cord:addr:remove']"
        >刷新缓存</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="srcAddrList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="出库单号" align="center" prop="warehouseEntryNumber" />
      <el-table-column label="条码" align="center" prop="barCode" />
      <el-table-column label="仓库" align="center" prop="wname" />
      <el-table-column label="入库方" align="center" prop="storageParty" />
      <el-table-column label="出库方" align="center" prop="outboundParty" />
      <el-table-column label="入库时间" align="center" prop="beginTime" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="批次号" align="center" prop="materialCode" />
      <el-table-column label="数量" align="center" prop="number" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">未出入库</span>
          <span v-if="scope.row.status==1">已入库</span>
          <span v-if="scope.row.status==2">已出库</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="超市名称" prop="name">
          <el-input v-model="form.name" placeholder="超市名称" />
        </el-form-item>
        <el-form-item label="负责人" prop="head">
          <el-input v-model="form.head" placeholder="负责人" />
        </el-form-item>
        <el-form-item label="手机号" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="地址详情" prop="tel">
          <el-input v-model="form.addr" placeholder="请输地址详情"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addType, srcOutList, updateType, delType, srcWearList} from "@/api/outhousing/outquery";


export default {
  name: "index.vue",
  data() {
    return {
      type:[],
      single:true,
      open:false,
      form:{},
      title:"",
      loading:true,
      srcAddrList:[],
      ids:[],
      queryParams:{
        id:undefined,
        pageNum: 1,
        pageSize: 10,

      },
      showSearch:true,
      total:0,
      rules:{
        name: [
          { required: true, message: "超市名称不能为空", trigger: "blur" }
        ],
        head: [
          { required: true, message: "负责人不能为空", trigger: "blur" }
        ],
        tel: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        addr: [
          { required: true, message: "地址详情不能为空", trigger: "blur" }
        ],
      }
    }
  },
  methods: {
    handleSelectionChange(selection){
      this.ids = selection.map(item => item.dictId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleQuery(){
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList(){
      srcOutList(this.queryParams).then(r=>{
        this.srcAddrList=r.rows;
        this.total=r.total;
        this.loading=false;
      })
    },
    resetQuery(){
      this.queryParams={};
      this.getList();
    },
    handleAdd(){
      this.open = true;
      this.title = "添加仓库";
    },
    submitForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateType(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addType(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });


    },
    handleDelete(row){

      const id = row.id || this.ids;
      this.$modal.confirm('是否确认删除仓库id为"' + id + '"的数据项？').then(function() {
        return delType(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    cancel(){
      this.open = false;
      this.reset();
    },
    handleUpdate(row){

      this.form=row;
      this.open=true;

    },
    wearList(){
      srcWearList().then(r=>{
        this.type=r.rows;
      })
    }

  },
  created() {
    this.getList();
    this.wearList();
  }
}
</script>

<style scoped>

</style>
